package com.littcore.saas.wechat.web;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.context.request.WebRequest;
import org.springframework.web.servlet.ModelAndView;

import com.littcore.common.Utility;
import com.littcore.dao.page.IPageList;
import com.littcore.dao.ql.PageParam;
import com.littcore.exception.NotLoginException;
import com.littcore.module.annotation.Func;
import com.littcore.saap.assistant.webservice.IQuickviewWebService;
import com.littcore.saap.common.vo.LoginUserVo;
import com.littcore.saap.core.common.SaapConstants;
import com.littcore.saap.core.web.util.LoginUtils;
import com.littcore.saas.wechat.service.ICpUserService;
import com.littcore.saas.wechat.service.IWechatCpService;
import com.littcore.web.mvc.action.BaseController;
import com.littcore.web.util.WebUtils;


/**
 * .
 * 
 * <pre><b>描述：</b>
 *    
 * </pre>
 * 
 * <pre><b>修改记录：</b>
 *    
 * </pre>
 * 
 * @author <a href="mailto:littcai@hotmail.com">蔡源</a>
 * @since 2015年9月24日
 * @version 1.0
 */
@Controller
public class CpUserController extends BaseController{
  
  @Resource
  private IQuickviewWebService quickviewService;
  @Resource
  private ICpUserService cpUserService;
  
  /**
   * Index.
   *
   * @param request the request
   * @param modelMap the model map
   * @return the model and view
   * @throws NotLoginException the not login exception
   */
  @Func(funcCode="query", moduleCode="tenant.wechat.cpUser", enableLog=false) 
  @RequestMapping 
  public ModelAndView index(WebRequest request, ModelMap modelMap)
  { 
    LoginUserVo loginUserVo = (LoginUserVo)super.getLoginVo();
    
    //读取快速视图定义    
    Map<String, Object> resultMap = quickviewService.generate("cpUser-quickview", loginUserVo, request);  
    modelMap.addAllAttributes(resultMap);
    
    return new ModelAndView("/wechat/cpUser/index");  
  
  }   
  
  @Func(funcCode="sync",moduleCode="tenant.wechat.cpUser")
  @RequestMapping 
  public void sync()
  {
    int tenantId = LoginUtils.getTenantId();
    cpUserService.doSync(tenantId);
  }
  
  @Func(funcCode="invite",moduleCode="tenant.wechat.cpUser")
  @RequestMapping 
  public void invite()
  {
    int tenantId = LoginUtils.getTenantId();
    cpUserService.doInvite(tenantId);
  }

  @Func(funcCode="invite",moduleCode="tenant.wechat.cpUser")
  @RequestMapping 
  public void inviteUser(@RequestParam int userId)
  {
    cpUserService.doInviteUser(userId);
  }
  
  //@Func(funcCode="invite",moduleCode="tenant.wechat.cpUser")
  @RequestMapping 
  public void sendMessage(@RequestParam int userId)
  {
    cpUserService.doSendMessage(userId, "测试测试");
  }
}
